package com.dwj.auto.comment.common.response;

import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.Data;

import java.util.List;

/**
 * @ClassName PageResponse
 * @Description 分页响应
 * @Author dwjian
 * @Date 2020/1/13 0:26
 */
@Data
public class PageResponse<T> extends Response<List<T>> {
    private long page;
    private long limit;
    private long count;

    private PageResponse(Response<List<T>> response, long page, long limit, long count) {
        this.setData(response.getData());
        this.setCode(response.getCode());
        this.setMsg(response.getMsg());
        this.setOK(response.isOK());
        this.page = page;
        this.limit = limit;
        this.count = count;
    }

    public static <T> PageResponse<T> success(IPage<T> page){
        Response<List<T>> response = success(page.getRecords());
        return new PageResponse<>(response , page.getCurrent(), page.getSize(), page.getTotal());
    }
}
